package com.hcbd.tdwt.ui.fuda.common.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.hcbd.tdwt.R;


public class AddChannelDialog extends Dialog implements View.OnClickListener {


    private EditText editContent;
    private TextView titleTV;

    private Button okBtn;
    private Button quiteBtn;
    private String title;
    private OnClickListener listener;
    public AddChannelDialog(Context context,String title,OnClickListener onClickListener) {
        super(context);
        this.title=title;
        this.listener=onClickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_add_channel);
        setCanceledOnTouchOutside(false);
        init();
    }

    public void init() {
        editContent = findViewById(R.id.edit_content);
        titleTV = findViewById(R.id.title);
        titleTV.setText(title);
        okBtn = findViewById(R.id.okBtn);
        quiteBtn = findViewById(R.id.quiteBtn);
        okBtn.setOnClickListener(this);
        quiteBtn.setOnClickListener(this);
    }


    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.okBtn:
                if (listener != null) {
                    listener.onOk(this, editContent.getText().toString().trim());
                }
                //editContent.setText("");
                break;
            case R.id.quiteBtn:
                this.dismiss();
            case R.id.shutDown:
                this.dismiss();
                break;
        }
    }

    public interface OnClickListener {
        void onOk(Dialog dialog, String content);
    }


    public static void show(Dialog dialog) {
        if (dialog != null && !dialog.isShowing()) {
            dialog.show();
        }
    }

    public static void shutDown(Dialog dialog) {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }
}